var t, a = require("../../../@babel/runtime/helpers/interopRequireDefault"), e = require("../../../@babel/runtime/helpers/toConsumableArray"), o = a(require("../../../@babel/runtime/regenerator")), n = require("../../../@babel/runtime/helpers/asyncToGenerator"), i = getApp(), r = require("../../../mybehaviors/location/location");

Page({
    behaviors: [ r ],
    data: {
        show: !1,
        communityStoreDetails: null,
        communityId: 0,
        Height: "340rpx",
        isMoreShow: !1,
        stores: [],
        point: {},
        address: "",
        city: "",
        search: "",
        preSearch: "",
        currentPage: 1,
        totalPage: 0,
        iPnoneBottomBol: !1,
        openTemplate: 0
    },
    onLoad: (t = n(o.default.mark(function t(a) {
        var e = this;
        return o.default.wrap(function(t) {
            for (;;) switch (t.prev = t.next) {
              case 0:
                this.getiPnoneBottom();
                try {
                    a.id ? this.setData({
                        communityId: a.id
                    }) : this.data.communityId || wx.navigateTo({
                        url: "/packageH/o2o/communityStore/communityStore"
                    }), this._getLocation(function(t, a) {
                        e._getData();
                    });
                } catch (t) {
                    console.error(t);
                }

              case 2:
              case "end":
                return t.stop();
            }
        }, t, this);
    })), function(a) {
        return t.apply(this, arguments);
    }),
    initData: function() {
        this.setData({
            stores: [],
            totalPage: 0,
            currentPage: 1
        });
    },
    _getData: function() {
        this.initData();
        var t = this, a = !1, e = i.getNetAddresss("plugin.store-community.frontend.community.getInfo");
        t.data.communityId ? i._getNetWork({
            url: e,
            data: {
                lng: t.data.point.lng,
                lat: t.data.point.lat,
                community_id: t.data.communityId,
                page: t.data.currentPage,
                kwd: t.data.search
            },
            success: function(e) {
                var o = e.data;
                if (1 === o.result) {
                    console.info(o);
                    var n = o.data.store_list, i = n ? n.data : [];
                    0 === i.length && (a = !0), o.data.info.explain && (o.data.info.explain = o.data.info.explain.replace(/<img/gi, '<img style="max-width:100%;height:auto;display:block"')), 
                    t.setData({
                        stores: i,
                        currentPage: n ? n.current_page : 0,
                        totalPage: n ? n.last_page : 0,
                        communityStoreDetails: o.data.info,
                        noDatas: a
                    }), wx.setNavigationBarTitle({
                        title: o.data.plugin_name
                    });
                }
            },
            fail: function(t) {
                console.log(t);
            }
        }) : t.setData({
            noDatas: !0
        });
    },
    tolocation: function() {
        var t = getCurrentPages(), a = t[t.length - 1], e = "/".concat(a.route, "?id=").concat(this.data.communityId);
        wx.setStorageSync("communityStoreDetailsUrl", e), wx.navigateTo({
            url: "/packageC/o2o/o2oLocation/o2oLocation?tag=communityStoreDetails"
        });
    },
    getiPnoneBottom: function() {
        try {
            wx.getStorageSync("iPhoneBottom") && this.setData({
                iPnoneBottomBol: !0
            });
        } catch (t) {}
    },
    showCommunityIntroduction: function() {
        this.setData({
            show: !0
        });
    },
    popupClose: function() {
        this.setData({
            show: !1
        });
    },
    getStoresBySearch: function() {
        var t = this.data.search.trim();
        t.trim() != this.data.preSearch && (this.setData({
            preSearch: t.trim()
        }), this._getData());
    },
    delHtmlTag: function(t) {
        return t.replace(/<[^>]+>/g, "").replace(/&nbsp;/gi, "");
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    _getMoreData: function() {
        var t = this, a = i.getNetAddresss("plugin.store-community.frontend.community.getInfo");
        i._getNetWork({
            url: a,
            data: {
                lng: t.data.point.lng,
                lat: t.data.point.lat,
                community_id: t.data.communityId,
                page: t.data.currentPage,
                kwd: t.data.search
            },
            success: function(a) {
                var o = a.data;
                if (1 === o.result) {
                    console.info(o);
                    var n = o.data.store_list, i = n ? n.data : [], r = [].concat(e(t.data.stores), e(i));
                    t.setData({
                        stores: r
                    });
                }
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    onReachBottom: function() {
        console.info(this.data.totalPage, this.data.currentPage), 0 !== this.data.totalPage && this.data.totalPage > this.data.currentPage && (this.setData({
            currentPage: this.data.currentPage + 1
        }), this._getMoreData());
    },
    onShareAppMessage: function() {}
});